package cn.itcast.utils;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;


import java.io.InputStream;

public class MapperUtils {
    private  static Object mapper = null;
    private MapperUtils(){}

    public static Object getMapper(Class<?> clazz){
        try {
            InputStream is = Resources.getResourceAsStream("sqlConfig.xml");
            SqlSessionFactory sessionFactory = new SqlSessionFactoryBuilder().build(is);
            SqlSession sqlSession = sessionFactory.openSession(true);
             mapper = sqlSession.getMapper(clazz);

        } catch (Exception e) {
            e.printStackTrace();
        }
        return mapper;
    }

}
